<!DOCTYPE html>
<html>
<title>JavaScript Switch Case语句示例 - 基础教程(cainiaojc.com)</title>

<body>

    <p> getDay()方法以0到6之间的数字返回工作日：</p>
    <p>此示例使用工作日编号来计算工作日名称：</p>
    <p>点击按钮以显示今天是星期几：</p>
    <button onclick="OWO()">Today</button>
    <p id="request"></p>


    <p>输入1到5之间的数字。</p>
    <p>如果省略break，程序将在switch语句中的下一条语句处继续执行：</p>
    <input type="text" onkeyup="ppt()">
    <p id="AuA"></p>

    <script>
        function OWO() {
            var day;
            switch (new Date().getDay()) {
                case 0:
                    day = "Sunday";
                    break;
                case 1:
                    day = "Monday";
                    break;
                case 2:
                    day = "Tuesday";
                    break;
                case 3:
                    day = "Wednesday";
                    break;
                case 4:
                    day = "Thursday";
                    break;
                case 5:
                    day = "Friday";
                    break;
                case 6:
                    day = "Saturday";
                    break;
                default:
                    day = "Undefined Day";
            }
            document.getElementById("request").innerHTML = "Today id " + day;
        }


        function ppt() {
            var text;
            var num = Number(document.querySelector("input").value);
            switch (num) {
                case 1:
                case 2:
                case 3:
                case 4:
                    text = "你输入的数字介于两者之间 1 - 4";
                    break;
                case 5:
                case 6:
                case 7:
                case 8:
                    text = "你输入的数字介于两者之间 5 - 8";
                    break;
                default:
                    text = "执行默认语句";
            }
            document.getElementById("AuA").innerHTML = text;
        }
    </script>

</body>

</html>